package com.cdut.logistics.model.dao.datacentre;

import java.util.Date;

import com.cdut.logistics.model.entity.datacentre.BaseSchool;
import com.jfinal.plugin.activerecord.Db;

/**  
 * @ClassName: school 
 * @Description: 操作数据库 
 * @author wxt.xia
 * @date 2018年1月26日 上午9:13:52    
 */
public class School extends BaseSchool<School>{
	private static final long serialVersionUID = 1L;
	public static School dao =new School();
	public String baseSql = " and is_use = 1";
	public String sql1 = "SELECT "+
			"school.id,"+
			"school.`name`, "+
			"province.name as 'p_name',"+
			"city.`name` as 'c_name',"+
			"street.`name` as 's_name' "+
			"from school JOIN province  ON school.`name` like ?  AND school.province = province.id  AND school.is_use = 1 "+
			"JOIN	city ON school.city = city.id AND city.is_use = 1 "+
			"JOIN	street ON school.street = street.id AND street.is_use = 1 ";
	public String sql2 = "SELECT "+
			"school.id,"+
			"school.`name`, "+
			"province.name as 'p_name',"+
			"city.`name` as 'c_name',"+
			"street.`name` as 's_name' "+
			"from school JOIN province  ON school.id = ?  AND school.province = province.id  AND school.is_use = 1 "+
			"JOIN	city ON school.city = city.id AND city.is_use = 1 "+
			"JOIN	street ON school.street = street.id AND street.is_use = 1 ";
			public String sql4 = "select * from school where school_id like ?"+ baseSql;
	public String sql3 = "UPDATE school set is_use =?, updated=? where id =?"+ baseSql;
	/**  
	 * @Title: save  
	 * @Description: 新增学校
	 * @author wxt.xia
	 * @param school
	 * @throws  
	 */
	public void save(School school) {
		school.set("created", new Date());
		school.set("updated", new Date());
		school.set("is_use", 1);
		school.set("active", 1);
		school.save();
	}

	/**  
	 * @Title: remove  
	 * @Description: 删除学校
	 * @author wxt.xia
	 * @param id
	 * @throws  
	 */
	public void remove(int id) {
		Db.update(sql3,0,new Date(),id);
	}

	/**  
	 * @Title: queryById  
	 * @Description: 根据学校id查询
	 * @author wxt.xia
	 * @param id
	 * @return
	 * @throws  
	 */
	public School queryById(int id) {
		return findById(id);
	}
}
